package main

import "strconv"

func evalRPN(tokens []string) int {
	var stack []int
	for _, token := range tokens {
		if token == "+" || token == "-" || token == "*" || token == "/" {
			o2 := stack[len(stack)-1]
			o1 := stack[len(stack)-2]
			stack = stack[:len(stack)-2]
			var ret int
			switch token {
			case "+":
				ret = o1 + o2
			case "-":
				ret = o1 - o2
			case "*":
				ret = o1 * o2
			case "/":
				ret = o1 / o2
			}
			stack = append(stack, ret)
		} else {
			v, _ := strconv.Atoi(token)
			stack = append(stack, v)
		}
	}
	return stack[0]
}

func main() {
	println(evalRPN([]string{
		"2", "1", "+", "3", "*",
	}))
}
